class Stack {
  constructor() {
    //栈中的元素
    this.items = [];
  }
  //栈常用方法
  //入栈
  push(el) {
    this.items.push(el);
  }
  //出栈
  pop() {
    return this.items.pop();
  }
  //查看栈顶元素
  peek() {
    return this.items[this.size() - 1];
  }
  //栈的长度
  size() {
    return this.items.length;
  }
  //判断栈的元素是否为空
  isEmpty() {
    return this.size() === 0;
  }
  //查看栈中所有元素
  toString() {
    return this.items.reduce((acc, curr) => (acc += curr + " "), "");
  }
}

const stack = new Stack();
stack.push(1);
stack.push(2);
console.log(stack.toString());
console.log(stack.peek());
console.log(stack.size());
console.log(stack.isEmpty());
